package site.xuqing.autohelperengine.local.overlay;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import site.xuqing.autohelperengine.R;
import site.xuqing.autohelperengine.StepManager;

public class InputView extends LinearLayout {
    EditText editText;
    Button confirm,cancel;
    public InputView(Context context) {
        this(context, null);
    }

    public InputView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.float_input, this);

        editText=findViewById(R.id.edit);
        confirm=findViewById(R.id.confirm);
        cancel=findViewById(R.id.cancel);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                InputView.this.onClick();
            }
        });
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                FloatViewManager.getInstance().hideInputView();
            }
        });
    }

    public void onClick(){
        if ("".equals(editText.getText().toString().trim())){
            FloatViewManager.getInstance().showMessageView("请输入步骤名称！");
        }else{
            if(StepManager.saveLocalSteps(editText.getText().toString().trim())){
                FloatViewManager.getInstance().showMessageView("保存成功！");
                FloatViewManager.getInstance().hideInputView();
            }else{
                FloatViewManager.getInstance().showMessageView("保存失败，名字重复或者步骤为空！");
            }
        }
    }
}
